//
//  Temp.swift
//  SwiftLoopers
//
//  Created by MAC on 2017/8/22.
//  Copyright © 2017年 Kevin. All rights reserved.
//

import UIKit

class Temp: BaseViewController {
    var count = 300
    var timer:Timer!
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        deallocTimer()
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "零时"
        timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(Temp.timerBySeaond), userInfo: nil, repeats: true)
        timer.fireDate = NSDate.distantPast
        // Do any additional setup after loading the view.
    }
    
    func timerBySeaond() {
        print("Timer: \(count)")
        count-=1
        if count<=0 {
            timer.fireDate = NSDate.distantFuture
           deallocTimer()
        }
    }
    func deallocTimer() {
        if timer != nil {
            timer.invalidate()
            timer = nil
        }
        
    }
    deinit {
        print("deinit")
    }
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        backBtnClicked(false)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
